const nums = [0,1, 2, 3, 4, 5, 6, ];
const target = 5;

function twoSum(arr, target) {
  let res = [];
    let i=0,j=arr.length
  while(i<j) {
    if (arr[i] + arr[j] === target) {
      res = [i, j];
      break;
    } else if (arr[i] + arr[j] < target) {
        i ++
    }else if(arr[i]+arr[j]>target) {
        j--
    }
  }
  return res;
}

console.log(twoSum(nums, target));
